/**
 * Created with IntelliJ IDEA.
 * Description:死锁代码
 * User: 87111
 * Date: 2025-11-12
 * Time: 18:29
 */
public class Demo3 {
    public static void main(String[] args) {
        Object locker1 = new Object();
        Object locker2 = new Object();
        Thread t1 = new Thread(() -> {
           try {
               synchronized (locker1) {
                   locker1.wait();
               }
               System.out.println("t1");
               synchronized (locker2) {
                   locker2.notify();
               }
           } catch (InterruptedException e) {
               throw new RuntimeException(e);
           }
        });
        Thread t2 = new Thread(() -> {
            try {
                synchronized (locker2) {
                    locker2.wait();
                }
                System.out.println("t2");
                synchronized (locker1) {
                    locker1.notify();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        t1.start();
        t2.start();
    }
}
